'use strict';

const BaseController = require('./baseController');

class FollowController extends BaseController {
    async index() {

    }

    //创建保存跟进记录
    async save(){
        const { ctx } = this;
        
        let params = ctx.request.body;

        let data = await ctx.service.follow.save(params, ctx.user);

        this.jsonSuccess(data);
    }


    async list(){
        const { ctx } = this;

        let params = ctx.request.body;

        let { list, count } = await ctx.service.follow.getList(params);

        //格式化返回数据
        list = list.map( async item => {
            let newData = ctx.helper.toCamel(item)
            newData.projectName = await ctx.service.project.getProjectName(newData.projectId);
            newData.userName = await ctx.service.user.getUserName(newData.userId);
            return newData;
        })

        list = await Promise.all(list);

        this.jsonSuccess({
            data: list,
            count: count
        });
    }


    async getNumInfo(){

        const { ctx } = this;

        let params = ctx.request.body;

        let list = await ctx.service.follow.getFollowNumInfo(params);

        this.jsonSuccess(list);

    }

    async getNumList(){
        const { ctx } = this;

        let params = ctx.request.body;

        let list = await ctx.service.follow.getFollowNumList(params);

        this.jsonSuccess(list);
    }

}

module.exports = FollowController;
